package com.bw.culture.view

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.constants.RoutePath
import com.bw.common.view.BaseMvvmActivity
import com.bw.culture.adapter.CultureAdapter
import com.bw.culture.databinding.ActivityCultureBinding
import com.bw.culture.net.CultureViewModel

/**
 * 智慧园区-文化管理
 * 园区新闻
 * 刘哲甫
 * 20250507
 */
@Route(path = RoutePath.PATH_CULTURE)
class CultureActivity : BaseMvvmActivity<ActivityCultureBinding,CultureViewModel>() {

    private lateinit var newsAdapter : CultureAdapter
    override fun initView() {
        binding.topBar.ivBack.setOnClickListener { finish() }
        binding.topBar.tvLeftTitle.text = "园区新闻"
        binding.topBar.tvLeftTitle.visibility = View.VISIBLE
        binding.topBar.tvTitle.visibility = View.GONE
        binding.topBar.ivAdds.visibility = View.VISIBLE

        binding.topBar.ivAdds.setOnClickListener {
            ARouter.getInstance().build(RoutePath.PATH_ADD_CULTURE).navigation()
        }

        newsAdapter = CultureAdapter()
        binding.rv.adapter = newsAdapter
        binding.rv.layoutManager = LinearLayoutManager(this)

    }

    override fun initData() {
        vm.newsSuccess.observe(this){
            ToastUtils.showShort(it.size)
            newsAdapter.data.clear()
            newsAdapter.data.addAll(it)
            newsAdapter.notifyDataSetChanged()
        }

    }

    override fun onResume() {
        super.onResume()
        vm.getNews()
    }

}